package com.nxj.rpc;

import com.nxj.rpc.server.RpcServer;
import org.I0Itec.zkclient.ZkClient;
import org.apache.zookeeper.CreateMode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ServerBootstrapApplication implements CommandLineRunner {


    @Autowired
    RpcServer rpcServer;

    public static void main(String[] args) {
        SpringApplication.run(ServerBootstrapApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        new Thread(new Runnable() {
            @Override
            public void run() {
                ZkClient zkClient = new ZkClient("113.31.147.93:2181");
                System.out.println(zkClient);
                System.out.println("2");
                String zkClient_create = zkClient.create("/netty_rpc/provider/127.0.0.1:8992", "8992", CreateMode.PERSISTENT);
                System.out.println(zkClient_create);
                rpcServer.startServer("127.0.0.1", 8992);
            }
        }).start();
    }
}
